<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table 
        ref="table" 
        size="middle" 
        :scroll="{x:true}" 
        bordered rowKey="id" 
        :columns="columns" 
        :dataSource="dataSource"
        :pagination="ipagination" 
        :loading="loading" 
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <v-if></v-if>

        <!-- <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template> -->

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a @click="getList(record.userId)">积分日志</a>
          <a-divider type="vertical" />
          <a v-if="record.status == 1" @click="closeIntegral(record)">关闭</a>
          <a v-else @click="openIntegral(record)">开启</a>
        </span>
        
        

      </a-table>
    </div>

    <integral-modal ref="modalForm" @ok="modalFormOk"></integral-modal>
    <integral-edit-modal ref="modalEditForm" @ok="modalFormOk"></integral-edit-modal>
    <!-- 积分日志记录 -->
    <test-modal ref="testModal" @ok="modalFormOk"></test-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import {
    mixinDevice
  } from '@/utils/mixin'
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import IntegralModal from './modules/IntegralModal'
  import IntegralEditModal from './modules/IntegralEditModal'
  import TestModal from './modules/TestModal'


  export default {
    name: "IntegralList",
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      IntegralModal,
      IntegralEditModal,
      TestModal
    },
    data() {
      return {
        description: '积分表管理页面',
        // 表头
        columns: [{
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function(t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '用户ID',
            align: "center",
            dataIndex: 'userId'
          },
          {
            title: '用户昵称',
            align: "center",
            dataIndex: 'nickname'
          },
          {
            title: '积分数',
            align: "center",
            dataIndex: 'integralNum'
          },
          {
            title: '手机号码',
            align: "center",
            dataIndex: 'mobilePhoneNumber'
          },
          {
            title: '积分状态',
            align: "center",
            dataIndex: 'status_dictText'
          },
          {
            title: '删除状态',
            align: "center",
            dataIndex: 'delFlag_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            fixed: "right",
            width: 147,
            scopedSlots: {
              customRender: 'action'
            }
          }
        ],
        url: {
          list: "/integral/integral/list",
          delete: "/integral/integral/delete",
          deleteBatch: "/integral/integral/deleteBatch",
          exportXlsUrl: "/integral/integral/exportXls",
          importExcelUrl: "integral/integral/importExcel",

        },
        dictOptions: {},
      }
    },
    created() {},
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      
      initIntegralData(){
         this.axios.get("/integral/integral/list").then((res) => {
           this.columns = res.data.records;
         })
      },
      handleEdit: function(record) {
        this.$refs.modalEditForm.edit(record);
        this.$refs.modalEditForm.title = "编辑";
        this.$refs.modalEditForm.disableSubmit = false;
      },
      closeIntegral(record) {
        this.axios.post('/integral/integral/closeIntegralStatusByUserId', record).then((res) => {
          console.log(res);
          this.loadData() ;
        })
      },
      openIntegral(record) {
        console.log(record);
        this.axios.post('/integral/integral/openIntegralStatusByUserId', record).then((res) => {
          console.log(res);
          this.loadData();
          // this.initIntegralData();
        })
      },
    getList(id) {
      this.$refs.testModal.getList(id)
      this.$refs.testModal.title = '积分日志'
      this.$refs.testModal.disableSubmit = true
    }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
